package com.fenghuajueli.module_home;

import android.content.Intent;
import android.graphics.Rect;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.ConvertUtils;
import com.fenghuajueli.libbasecoreui.viewmodel.BaseViewModelFragment2;
import com.fenghuajueli.module_home.adapter.HomeToolsAdapter;
import com.fenghuajueli.module_home.bean.HomeToolsBean;
import com.fenghuajueli.module_home.databinding.FragmentHomePageBinding;
import com.fenghuajueli.module_home.model.HomePageModel;
import com.fenghuajueli.module_route.CunQianJiZhangModuleRoute;
import com.fenghuajueli.module_route.HomeModuleRoute;
import com.fenghuajueli.module_route.MattersModuleRoute;
import com.fenghuajueli.module_route.MemoModuleRoute;
import com.fenghuajueli.module_route.NoteModuleRoute;
import com.fenghuajueli.module_route.TargetModuleRoute;
import com.fenghuajueli.module_route.TimeBlockModuleRoute;
import com.fenghuajueli.module_route.ZhuanZhuModuleRoute;

/**
 * 主页界面
 */
@Route(path = HomeModuleRoute.HOME_PAGE)
public class HomePageFragment extends BaseViewModelFragment2<HomePageModel, FragmentHomePageBinding> {


    //fragment传递参数示例  kotlin需要加上@JvmField
    @Autowired(name = "name")
    String name;

    @Override
    protected HomePageModel createViewModel() {
        return new HomePageModel();
    }

    @Override
    protected FragmentHomePageBinding createViewBinding() {
        return FragmentHomePageBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void initView(View containerView) {
        binding.recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
                super.getItemOffsets(outRect, view, parent, state);
                int buttom = 0;
                int position = parent.getChildAdapterPosition(view);
                if (position == HomeToolsBean.getHomeToolsData().size() - 1) {
                    buttom = ConvertUtils.dp2px(20);
                }
                outRect.set(0, 0, 0, buttom);
            }
        });
        binding.recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        HomeToolsAdapter adapter = new HomeToolsAdapter(HomeToolsBean.getHomeToolsData());
        binding.recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new HomeToolsAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(String name) {
                if ("目标".equals(name)) {
                    ARouter.getInstance().build(TargetModuleRoute.TARGET_LIST_ACTIVITY).navigation();
                } else if ("事项".equals(name)) {
                    ARouter.getInstance().build(MattersModuleRoute.MATTERS_ACTIVITY).navigation();
                } else if ("备忘录".equals(name)) {
                    ARouter.getInstance().build(MemoModuleRoute.MEMO_ACTIVITY).navigation();
                } else if ("打卡".equals(name)) {
                    ARouter.getInstance().build(TimeBlockModuleRoute.TIME_BLOCK_ACTIVITY).withInt("position", 0).navigation();
                } else if ("记账存钱".equals(name)) {
//                    ARouter.getInstance().build(CunQianJiZhangModuleRoute.JI_ZHANG_ACTIVITY).navigation();
                } else if ("日记".equals(name)) {
//                    startActivity(new Intent(requireContext(), FileListActivity.class));
                } else if ("专注模式".equals(name)) {
                    ARouter.getInstance().build(ZhuanZhuModuleRoute.ACTIVITY_ZHUANZHU_SETTING).navigation();
                }
            }
        });
    }

    @Override
    protected void initData() {

    }
}